package util.boyaa
{
	import com.boyaa.shells.control.LayerManager;
	import com.boyaa.shells.GameConfig;
	import com.boyaa.shells.tool.TooltipBase;
	import com.boyaa.shells.view.GetProp;
	import flash.display.MovieClip;
	
	/**
	 * 加载动画
	 * @author fly
	 */
	public class LoadData 
	{
		/** 当前还有多少请求未完成 */
		static private var _nActiveReq:int = 0;
		
		static private var _view:MovieClip;
		static private var _ani:MovieClip = null;
		static private var _bg:MovieClip = null;
		
		public function LoadData() 
		{
		}
		
		public function show():void
		{
			//try {""[2]}catch (e:Error){trace("LoadData.show()"+e.getStackTrace());}//1行输出堆栈
			if (_nActiveReq <= 0) {
				_nActiveReq = 0;
				_view = GetProp.getResourceByName("ViewLoadData");
				_ani = _view.ani;
				_view.x = GameConfig.DIMENSIONS.x / 2;
				_view.y = GameConfig.DIMENSIONS.y / 2;
				_bg = GetProp.getResourceByName("ViewBG");
				LayerManager.instance.addToLayer(LayerManager.TIPS_LAYER, _bg);
				LayerManager.instance.addToLayer(LayerManager.TIPS_LAYER, _view);
				
				_ani.play();
				_view.ani1.play();
				_view.ani2.play();
			}
			_nActiveReq++;
			//trace("...小人跑啊跑");
		}
		
		public function hide():void
		{
			//try {""[2]}catch (e:Error){trace("LoadData.hide()"+e.getStackTrace());}//1行输出堆栈
			if (_nActiveReq > 0)
				_nActiveReq--;
			if (_nActiveReq <= 0 && _view != null) {
				_ani.stop();
				_view.ani1.stop();
				_view.ani2.stop();
				_bg.parent && _bg.parent.removeChild(_bg);
				_view.parent && _view.parent.removeChild(_view);
				ContainerClear.removeAllChild(_view);
			}
		}
		
		static public function get nActiveReq():int 
		{
			return _nActiveReq;
		}
		
		public function clearAll():void
		{
			_nActiveReq = 1;
			hide();
		}
	}

}